class CreateStructures < ActiveRecord::Migration
  def self.up
    create_table :structures do |t|
      t.string    :title, :null=>false
      t.string    :slug, :null=>false, :limit=>25
      t.integer   :kind, :limit=>1, :default=>0
      t.integer   :position, :limit=>2, :default=>0
      t.boolean   :is_visible, :default=>1
      
      t.integer   :posts_count, :default=>0
      t.integer   :contents_count, :default=>0
      
      t.integer  "parent_id"
      t.integer  "lft",                          :default => 0
      t.integer  "rgt",                          :default => 0
      t.integer  "cached_level",                 :default => 0
      
      t.timestamps
    end
    
    add_index :structures, :slug, :uniq=>true
    add_index :structures, :parent_id, :name=>"fk_parent"
    add_index :structures, [:lft, :rgt], :name=>"idx_lr"
    
    Structure.create_translation_table! :title => :string
  end

  def self.down
    drop_table :structures
    Structure.drop_translation_table!
  end
end
